<?php

abstract class Veneer_Controller_Block extends Zend_Controller_Action
{
/*	Variables
	array - jsZone

	add caching
*/
    protected $_dbArray =array();
    protected $_moduleName = null;
    protected $_module_id = 0;
    protected $_config_module;
    protected $_primary_table;

	protected $_veneer_parms;	// array of parms
	protected $_veneer_log;	// array of parms
	protected $_site_config;
	protected $_msite_config;
	protected $_defaultAction = "view";	// array of parms
	protected $_auth;	// login
	protected $_dbAdapter;	// login
	protected $_registry;	// login
	protected $_debug;	// login

	function init()
	{

		$this->_registry = Zend_Registry::getInstance();
		$this->_msite_config = $this->_registry->get('msite_config');
		$this->_site_config = $this->_registry->get('site_config');
		$this->_dbAdapter = $this->_registry->get('dbAdapter');
		$this->_veneer_log = $this->_registry->get('veneerLog');
		$this->_debug = $this->_registry->get('veneer_debug');
		$this->_veneer_parms = $this->_getAllParams();

		$this->view->baseUrl = $this->_request->getBaseUrl();
		foreach($this->_dbArray as $tableName)
		{
			Zend_Loader::loadClass($tableName,'modules/'. $this->_moduleName . '/models');
		}
	}

 	function preDispatch()
	{//*******************************************************
		// authorization
		// security
	}
    public function indexAction()
    {
		//should not be possible
    }

    public function adminLinkAction()
    {
		if(isset($this->veneer_parms['module']))
			$this->view->moduleName = $this->veneer_parms['module'];
		else
			$this->view->moduleName = 'default';
    }

   	public function __call($method, $args)
    {
		 if ('Action' == substr($method, -6)) {
            // If the action method was not found
			if(!file_exists(APP_PATH . 'modules/'.$this->_moduleName.'/views/scripts/block/'.substr($method, 0,-6).'.phtml')) {
				// file does not exist
					print APP_PATH . 'modules/'.$this->_moduleName.'/views/scripts/block/'.substr($method, 0,-6).'.phtml<br>';
					$this->_debug->print_r($this->_veneer_parms);
					$this->_helper->viewRenderer->renderScript('veneerErrorBlock.phtml');
			}
        }
    }
}

